/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package edu.upn.sigemfi.rec.bc;

import edu.upn.sigemfi.rec.be.AccionCobranza;
import java.util.logging.Level;
import java.util.logging.Logger;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

/**
 *
 * @author Programador
 */
public class AccionCobranzaDelegate {

    private AccionCobranzaFacadeLocal local;

    public AccionCobranzaDelegate() {
        local = lookupAccionCobranzaFacade();
    }

    private AccionCobranzaFacadeLocal lookupAccionCobranzaFacade() {
        try {
            Context c = new InitialContext();
            return (AccionCobranzaFacadeLocal) c.lookup("java:comp/env/AccionCobranzaFacade");
        } catch (NamingException ne) {
            Logger.getLogger(getClass().getName()).log(Level.SEVERE, "exception caught", ne);
            throw new RuntimeException(ne);
        }
    }

    public void crear(AccionCobranza AccionCobranza) throws Exception {
        try {
            local.create(AccionCobranza);
        } catch (Exception e) {
            local = lookupAccionCobranzaFacade();
            throw new Exception("Crear AccionCobranza. " + e.getMessage());
        }
    }

    public void editar(AccionCobranza AccionCobranza) throws Exception {
        try {
            local.edit(AccionCobranza);
        } catch (Exception e) {
            local = lookupAccionCobranzaFacade();
            throw new Exception("Editar AccionCobranza. " + e.getMessage());
        }
    }

    public void eliminar(AccionCobranza AccionCobranza) throws Exception {
        try {
            local.remove(AccionCobranza);
        } catch (Exception e) {
            local = lookupAccionCobranzaFacade();
            throw new Exception("Eliminar AccionCobranza. " + e.getMessage());
        }
    }

    public AccionCobranza buscar(long codigo) throws Exception {
        try {
            return local.find(codigo);
        } catch (Exception e) {
            local = lookupAccionCobranzaFacade();
            throw new Exception("Buscar AccionCobranza. " + e.getMessage());
        }
    }
}
